package servlet.servlet_yaobo;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import pojo.MembershipManagement;
import pojo.User;
import service.impl.ImpShoppingMemberService;
import util.JsonDateValueProcessor;
import util.PageBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 此类用于获取对会员管理进行操作
 */
@WebServlet(value = "/member")
public class ViewUserHarvestOrders extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        ImpShoppingMemberService imp=new ImpShoppingMemberService();
        PageBean<User> me=new PageBean<User>();
        String index=req.getParameter("page");
        if(index==null){
            me.setPageIndex(1);
        }else {
            me.setPageIndex(Integer.parseInt(index));
        }
        String ename=req.getParameter("demoReload");
        if(ename!=null){
            ename=new String(ename.getBytes("ISO-8859-1"),"UTF-8");
        }
        me.setPageSize(5);
        me=imp.memberUser(me,ename);
        JSONObject obj=new JSONObject();
        obj.put("code",0);
        obj.put("mag","");
        obj.put("count",me.getTotalCount());
        JsonConfig config=new JsonConfig();
        config.registerJsonValueProcessor(java.util.Date.class,new JsonDateValueProcessor());
        obj.put("data",JSONArray.fromObject(me.getList(),config));
        PrintWriter out=resp.getWriter();
        out.println(obj);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
